package cn.fz.service.impl;

import cn.fz.entity.ClazzCountOption;
import cn.fz.entity.JobOption;
import cn.fz.mapper.EmpMapper;
import cn.fz.mapper.StudentMapper;
import cn.fz.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption empJobData() {
        List<Map<String,Object>> list = empMapper.countByJob();

        // List jobList = new ArrayList();
        // for (Map map : list) {
        //     jobList.add(map.get("pos"));
        // }
        //1.获取jobList职位列表
        List<String> jobList = list.stream().map(item -> item.get("pos").toString()).toList();

        //2.获取dataList各职位总人数列表
        List<Integer> dataList = list.stream().map(item -> Integer.parseInt(item.get("sum").toString())).toList();

        //3.封装JobOption对象，并返回
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> empGenderData() {
        //调用mapper，获取员工性别数据
        return empMapper.countByGender();
    }

    @Override
    public List<Map<String,Object>> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    @Override
    public ClazzCountOption getStudentCountData() {
        List<Map<String, Object>> countList = studentMapper.getStudentCount();
        if(!CollectionUtils.isEmpty(countList)){
            List<String> clazzList = countList.stream().map(map -> map.get("cname").toString()).toList();

            List<Integer> dataList = countList.stream().map(map -> Integer.valueOf(map.get("scount").toString())).toList();

            return new ClazzCountOption(clazzList, dataList);
        }
        return null;
    }
}
